task :erase_deployment_data do
  set :erase_confirmation, ask("Are you sure? This will erase ALL deployment data from ALL servers", "YES/no")
  
  unless "YES" == fetch(:erase_confirmation, false)
    run_locally do
      error "Aborted erasure of deployment data."
    end
    
    next
  end
  
  on roles(:app) do |server|
    if test("[ -d #{release_path} ]")
      within release_path do
        info "Deleting the WordPress database #{server.user}@#{server.hostname}"
        
        execute :wp, :db, :reset, "--yes"
      end
    end
    
    if test("[ -d #{fetch(:deploy_to)} ]") or test("[ -f #{fetch(:deploy_to)} ]") or test("[ -h #{fetch(:deploy_to)} ]")
      info "Deleting the deployment directory from #{server.user}@#{server.hostname}"
      
      execute :rm, "-rf", fetch(:deploy_to)
    end
    
    if test("[ -d #{fetch(:website_root)} ]") or test("[ -f #{fetch(:website_root)} ]") or test("[ -h #{fetch(:website_root)} ]")
      info "Deleting the website root directory from #{server.user}@#{server.hostname}"
      
      execute :rm, "-rf", fetch(:website_root)
    end
    
    info "Creating an empty directory at the website root on #{server.user}@#{server.hostname}"
    
    execute :mkdir, "-p", fetch(:website_root)
    
    info "Creating a blank index file in the website root on #{server.user}@#{server.hostname}"
    
    execute :touch, File.join(fetch(:website_root), "index.html")
  end
end
